//
//  ButtonTableViewCell.m
//  NewMusic
//
//  Created by dllo on 15/11/22.
//  Copyright © 2015年 Going. All rights reserved.
//

#import "ButtonTableViewCell.h"

@interface ButtonTableViewCell ()
@property (nonatomic, retain) NSArray *arr;
@end

@implementation ButtonTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        [self creatSubView];
    }
    return self;
}
- (void)creatSubView
{
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString *str = [user objectForKey:@"MusicType"];
    self.arr = [NSArray arrayWithObjects:@"压缩", @"标准", @"超高", nil];
    for (NSInteger i = 0; i < 3; i++)
    {
        UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
        button.frame = CGRectMake(70 + 70 * i, 5, 50, 30);
        [button setTitle:self.arr[i] forState:UIControlStateNormal];
        button.layer.cornerRadius = 6;
        [button addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
        button.tag = 10000 + i;
        button.titleLabel.font = [UIFont systemFontOfSize:15.0];
        button.layer.borderColor = [UIColor colorWithRed:56 / 255.0 green:192 / 255.0 blue:107 / 255.0 alpha:1.0].CGColor;
        button.layer.borderWidth = 1;
        [self.contentView addSubview:button];
        if ([str isEqual:[NSString stringWithFormat:@"%@品质", self.arr[i]]])
        {
            button.backgroundColor = [UIColor colorWithRed:56 / 255.0 green:192 / 255.0 blue:107 / 255.0 alpha:1.0];
        }
    }
}
- (void)buttonAction:(UIButton *)sender
{
    UIButton *buttonOne = (UIButton *)[self.contentView viewWithTag:10000];
    UIButton *buttonTwo = (UIButton *)[self.contentView viewWithTag:10001];
    UIButton *buttonThree = (UIButton *)[self.contentView viewWithTag:10002];
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    [user setObject:[NSString stringWithFormat:@"%@品质", self.arr[sender.tag - 10000]] forKey:@"MusicType"];
    if (sender == buttonOne)
    {
        buttonOne.backgroundColor = [UIColor colorWithRed:56 / 255.0 green:192 / 255.0 blue:107 / 255.0 alpha:1.0];
        buttonTwo.backgroundColor = [UIColor clearColor];
        buttonThree.backgroundColor = [UIColor clearColor];
    } else if (sender == buttonTwo) {
        buttonTwo.backgroundColor = [UIColor colorWithRed:56 / 255.0 green:192 / 255.0 blue:107 / 255.0 alpha:1.0];
        buttonOne.backgroundColor = [UIColor clearColor];
        buttonThree.backgroundColor = [UIColor clearColor];
    } else {
        buttonThree.backgroundColor = [UIColor colorWithRed:56 / 255.0 green:192 / 255.0 blue:107 / 255.0 alpha:1.0];
        buttonOne.backgroundColor = [UIColor clearColor];
        buttonTwo.backgroundColor = [UIColor clearColor];
    }
    
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
